package com.qf.mybatisplus.rabbitMQ;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

//@Component
public class RouteConsumer {

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,    // 创建临时队列
                    exchange = @Exchange(value = "boot-route-exchange",type = "direct"),
                    key = {"info","error"}
            )
    }
    )
    public void getMessage1(String msg, Channel channel, Message message) throws Exception {
        TimeUnit.SECONDS.sleep(1);
        System.err.println("消费者1收到: "+msg);
        // 手动  ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,    // 创建临时队列
                    exchange = @Exchange(value = "boot-route-exchange",type = "direct"),
                    key = {"info"}
            )
    }

    )
    public void getMessage2(String msg, Channel channel, Message message) throws Exception {
        TimeUnit.SECONDS.sleep(1);
        System.err.println("消费者2收到: "+msg);
        // 手动  ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


}
